﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace pxt
{
    public class TongaTimer
    {
        private double total_duration;
        private double elapsed_time = 0;
        private bool paused = false;

        // Create a timer that lasts <time_in_seconds> long 
        public TongaTimer(double time_in_seconds)
        {
            total_duration = time_in_seconds * 1000;
        }

        public bool Check()
        {
            if (paused)
            {
                return false;
            }
            else
            {
                return (elapsed_time >= total_duration);
            }
        }

        public void Update(GameTime gameTime)
        {
            if (!paused)
            {
                elapsed_time += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            }
        }

        public void Reset()
        {
            elapsed_time = 0;
        }
        public void Pause()
        {
            paused = true;
        }

        public void Unpause()
        {
            paused = false;
        }

        public double Time
        {
            set { total_duration = value * 1000; }
            get { return total_duration; }
        }

        public double ElapsedTime
        {
            get { return elapsed_time; }
        }
    }
}
